package com.service.single.config;

import org.apache.http.HttpHost;
import org.elasticsearch.client.IndicesClient;
import org.elasticsearch.client.RestClient;
import org.elasticsearch.client.RestClientBuilder;
import org.elasticsearch.client.RestHighLevelClient;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @Author: 一休
 * @DateTime: 2022/11/3 15:39
 */
@Configuration
public class EsClientConfig {

    @Value("${es.hostname:192.168.10.7}")
    private String hostname;

    @Bean
    public RestHighLevelClient restHighLevelClient() {
        RestClientBuilder builder = RestClient.builder(new HttpHost(hostname, 9200, "http"));
        return new RestHighLevelClient(builder);
    }


    @Bean
    public IndicesClient indicesClient() {
        return restHighLevelClient().indices();
    }

}
